#include "byte_queue.h"

int16 ByteQueue_dequeue(sByteQueue* queue)	{
	if (queue->o == queue->i) {
		return -1;
	}
	else {
		uint8 b = queue->buf[queue->o];
		queue->o++;	queue->o &= queue->mask;
		return b;
	}
}

int8 ByteQueue_enqueue(sByteQueue* queue, byte b)	{
	queue->buf[queue->i] = b;
	queue->i++;	queue->i &= queue->mask;
	if (queue->o == queue->i) {
		queue->i--;	queue->i &= queue->mask;
		return -1;
	}
	else {
		return 0;
	}
}

void ByteQueue_init(sByteQueue* queue, uint8* buf, uint16 size) {
	queue->i = 0;
	queue->o = 0;
	queue->mask = size - 1;
	queue->buf = buf;
}

